<%  
    /* 枚举类 */
    var Enumerable=
    {
        all:function($iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _result=true;
            this.each
            (
                function($value,$index) 
                {                    
                    _result=_result&&!!$iterator($value,$index);
                    if(!_result) throw cusFrameworkDo$Break;
                }
            );
            return _result;
        },    
        any:function($iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _result=false;
            this.each
            (
                function($value,$index) 
                {
                    if(_result=!!$iterator($value,$index))
                    throw cusFrameworkDo$Break;
                }
            );
            return _result;
        },    
        collect:function($iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _results=[];
            this.each
            (
                function($value,$index) 
                {
                    _results.push($iterator($value,$index));
                }
            );
            return _results;
        },    
        detect:function($iterator,$context) 
        {
            $iterator=$iterator.bind($context);
            var _result;
            this.each
            (
                function($value,$index) 
                {
                    if($iterator($value,$index)) 
                    {
                        _result=$value;
                        throw cusFrameworkDo$Break;
                    }
                }
            );
            return _result;
        },        
        each:function($iterator,$context) 
        {
            var _index=0;
            $iterator=$iterator.bind($context);
            try 
            {
                this._each
                (
                    function($value)
                    {
                        $iterator($value,_index++);
                    }
                );
            }catch(e) 
            {
                if(e!=cusFrameworkDo$Break) throw e;            
            }
            return this;
        },    
        eachSlice:function($number,$iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _index=-$number,_slices=[],_array=this.toArray();
            while((_index+=$number)<_array.length)
            {                        
                _slices.push(_array.slice(_index,_index+$number));                
            }
            return _slices.collect($iterator,$context);
        },        
        findAll:function($iterator,$context) 
        {
            $iterator=$iterator.bind($context);
            var _results=[];
            this.each
            (
                 function($value,$index) 
                {
                    if($iterator($value,$index))
                    _results.push($value);
                }
            );
            return _results;
        },    
        grep:function($filter,$iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _results=[];            
            if(Object.isString($filter)){
                $filter=new RegExp($filter);
            }            
            this.each
            (
                function($value,$index) 
                {
                    if($filter.match($value)){
                        _results.push($iterator($value,$index));
                    }
                }
            );
            return _results;
        },
        include:function($object) 
        {
            if(Object.isFunction(this.indexOf))            
                if(this.indexOf(object) != -1) return true;            
            var _found=false;
            this.each
            (
                function($value) 
                {
                    if($value==$object) 
                    {
                        _found = true;
                        throw cusFrameworkDo$Break;
                    }
                }
            );
            return _found;
        },    
        inGroupsOf:function($number,$fillWith) 
        {
            $fillWith=$fillWith===undefined ? null:$fillWith;
            return this.eachSlice
            (
                 $number,
                function($slice)
                {                                                   
                    while($slice.length<$number) 
                    {
                        $slice.push($fillWith);
                    }
                    return $slice;
                }
            );
        },    
        inject:function($memo,$iterator,$context) 
        {    
            $iterator=$iterator.bind($context);    
            this.each
            (
                function($value,$index) 
                {                    
                    $memo=$iterator($memo,$value,$index);
                }
            );
            return $memo;
        },
        inspect:function() 
        {
            return '#<Enumerable:' + this.toArray().inspect() + '>';
        },        
        invoke:function($method) 
        {
            var _args=$A(arguments).slice(1);
            return this.map
            (
                function($value) 
                {
                    return $value[$method].apply($value,_args);
                }
            );
        },    
        max:function($iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _result;
            this.each
            (
                function($value,$index) 
                {
                    $value=$iterator($value,$index);
                    if(_result==undefined||$value>=_result)
                    _result=$value;
                }
            );
            return _result;
        },    
        min:function($iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _result;
            this.each
            (
                function($value,$index) 
                {
                    $value=$iterator($value,$index);
                    if(_result==undefined||$value<_result)
                    _result=$value;
                }
            );
            return _result;
        },    
        partition:function($iterator,$context) 
        {
            $iterator=$iterator ? $iterator.bind($context):cusFrameworkDoPrototypeK;
            var _trues=[],_falses=[];
            this.each
            (
                function($value,$index) 
                {
                    ($iterator($value,$index) ? _trues:_falses).push($value);
                }
            );
            return [_trues,_falses];
        },    
        pluck:function($property) 
        {
            var _results=[];
            this.each
            (
                function($value) 
                {
                    _results.push($value[$property]);
                }
            );
            return _results;
        },    
        reject:function($iterator,$context) 
        {
            $iterator=$iterator.bind($context);
            var _results=[];
            this.each
            (
                function($value,$index) 
                {
                    if(!$iterator($value,$index))
                    _results.push($value);
                }
            );
            return _results;
        },    
        size:function() 
        {
            return this.toArray().length;
        },            
        sortBy:function($iterator,$context) 
        {
            $iterator=$iterator.bind($context);
            return this.map
            (
                function($value,$index) 
                {                    
                    return {value:$value,criteria:$iterator($value,$index)};
                }
            ).sort
            (
                function($left,$right) 
                {                        
                    var _$a=$left.criteria,_$b=$right.criteria;
                    return _$a<_$b ? -1:(_$a>_$b ? 1:0);
                }
            ).pluck('value');
        },    
        toArray:function() 
        {
            return this.map();
        },    
        zip:function() 
        {
            var _iterator=cusFrameworkDoPrototypeK,_args=$A(arguments);
            if(Object.isFunction(_args.last()))
                _iterator=_args.pop();
            
            var _collections=[this].concat(_args).map($A);
            return this.map
            (
                function($value,$index) 
                {                    
                    return _iterator(_collections.pluck($index));
                }
            );
        }
    };
    //->别名
    Object.extend
    (
        Enumerable, 
        {
            map:Enumerable.collect,
            find:Enumerable.detect,
            select:Enumerable.findAll,
            filter:Enumerable.findAll,
            member:Enumerable.include,
            entries:Enumerable.toArray,
            every:Enumerable.all,
            some:Enumerable.any
        }
    );    
%>